//
//  Movie2ViewController.m
//  UI_元旦豆瓣电影
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "Movie2ViewController.h"
#import "Movie2CollectionViewCell.h"
#import "MovieViewController.h"
#import "MovieModel.h"
@interface Movie2ViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) UICollectionViewFlowLayout *layout;


@end

@implementation Movie2ViewController

- (void)dealloc {
    [_collection release];
    [_layout release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0 green:0.4 blue:0.5 alpha:1];
    self.navigationItem.title = @"电影";
    [self barButton];
    [self createCollection];
  
}

- (void)barButton {
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_list@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.rightBarButtonItem = item;
    [item release];
}

- (void)itemAction:(UIBarButtonItem *)item {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _arrM.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    Movie2CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    MovieModel *mod = _arrM[indexPath.row];
    cell.model2 = mod;
    
    return cell;
}

- (void)createCollection {
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    _layout.itemSize = CGSizeMake((375 - 40) / 3, 200);
    _layout.minimumInteritemSpacing = 10;
    _layout.minimumLineSpacing = 10;
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    self.collection = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:_layout];
    _collection.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_collection];
    [_collection release];
    _collection.delegate = self;
    _collection.dataSource = self;
    
    [_collection registerClass:[Movie2CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
